package com.niiwoo.civet.trade.service.local.loan;

import com.niiwoo.civet.trade.dao.mapper.ProjectMapperExt;
import com.niiwoo.civet.trade.dto.response.loan.LoanLimitResponseDTO;
import com.niiwoo.civet.trade.enums.ProjectFromSourceEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Slf4j
@Service
public class SpeedLoanLimitService {

    @Autowired
    private ProjectMapperExt projectMapperExt;

    /**
     * 查询审核中或未结清标的数量
     * @param userId
     * @return
     */
    public LoanLimitResponseDTO getProjectInApproveOrNotSettled(String userId){
        LoanLimitResponseDTO loanLimitResponseDTO = new LoanLimitResponseDTO();
        Integer projectInApproveNum = projectMapperExt.queryProjectInApprove(userId);
        loanLimitResponseDTO.setProjectNumInApprove(projectInApproveNum);
        Integer projectNotSettledNum = projectMapperExt.queryProjectNotSettled(userId);
        loanLimitResponseDTO.setProjectNumNotSettled(projectNotSettledNum);
        return loanLimitResponseDTO;
    }

    /**
     * 查询用户审核中或未结清标的数量,限定标的来源
     *
     * @param userId
     * @param fromSource
     * @return
     */
    public LoanLimitResponseDTO getProjectInApproveOrNotSettled(String userId, ProjectFromSourceEnum fromSource) {
        LoanLimitResponseDTO loanLimitResponseDTO = new LoanLimitResponseDTO();
        Integer projectInApproveNum = projectMapperExt.queryProjectInApproveWithFromSource(userId,fromSource.getType().intValue());
        loanLimitResponseDTO.setProjectNumInApprove(projectInApproveNum);
        Integer projectNotSettledNum = projectMapperExt.queryProjectNotSettledWithFromSource(userId,fromSource.getType().intValue());
        loanLimitResponseDTO.setProjectNumNotSettled(projectNotSettledNum);
        return loanLimitResponseDTO;
    }
}
